package net.cn_su.sharpeyes.orgchoose;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.hb.views.PinnedSectionListView;

import net.cn_su.sharpeyes.beans.Organization;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

import java.util.List;

/**
 * Created by Overlord on 2016/08/16.
 * Singularity Universe
 */
@EBean
public class OrgChooseAdapter extends BaseAdapter
        implements PinnedSectionListView.PinnedSectionListAdapter {

    private List<Organization> organizations = null;

    @RootContext
    protected Context context;

    public void bindData(List<Organization> organizations){

        this.organizations = organizations;
    }

    @Override
    public int getItemViewType(int position) {
        return organizations.get(position).getOrg_type();
    }

    @Override
    public boolean isItemViewTypePinned(int viewType) {
        return viewType == 1;
    }

    @Override
    public int getCount() {
        return organizations.size()==0?0:organizations.size();
    }

    @Override
    public Organization getItem(int i) {
        return organizations.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Organization org = getItem(i);


        if(org.getOrg_type() == 1){
            //乡镇

            TownshipListItem _view = TownshipListItem_.build(context);
            _view.bindDate(org);
            return _view;
        }else{
            //村

            VillageListItem _view = VillageListItem_.build(context);
            _view.bindDate(org);
            return _view;
        }
    }
}
